#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    double calculateTax(vector<vector<int>>& brackets, int income) {
        if (income == 0)
            return 0;
        double Ad = 0.0;
        for (int i = 0; i < brackets.size(); ++i)
        {
            if (i == 0)
            {
                if (income > brackets[i][0])
                {
                    Ad += brackets[i][0] * (brackets[i][1] / 100.0);
                    income -= brackets[i][0];
                }
                else {
                    Ad += income * (brackets[i][1] / 100.0);
                    break;
                }
            }
            else
            {
                if (income > (brackets[i][0] - brackets[i - 1][0]))
                {
                    Ad += (brackets[i][0] - brackets[i - 1][0]) * (brackets[i][1] / 100.0);
                    income -= (brackets[i][0] - brackets[i - 1][0]);
                }
                else
                {
                    Ad += income * (brackets[i][1] / 100.0);
                    break;
                }
            }
        }

        return Ad;
    }
};